import { getRouterParam } from 'h3'
import { getAppsData } from '~/server/plugins/apps'

export default defineEventHandler(async (event) => {
    const categoryName = getRouterParam(event, 'category')
    
    try {
        // 从内存中获取所有应用数据
        const allApps = getAppsData()

        // 根据分类名称过滤应用
        const resultApps = allApps.filter(app => {
            return app.category === categoryName
        }).slice(0, 12)
        
        return resultApps
    } catch (error) {
        console.error('Error reading apps:', error)
        return []
    }
})